local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_PlayerComponent(),"HomeButton_"..script.Name);
local HomeGui= ClientOHOH.load.UIManager().ui_list.HomeGui
local Rebirth_Cfg=ClientOHOH.config.Rebirth

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

   

	self.DataStore=self.parent:GetComponent(_G.ClientOHOH.load.Client_PlayerDataComponent())
    
    self.ConList={}

    if self.DataStore:GetData("base").rebirth>0 then
        self:AddProcess(function()
             self:dtor()
        end)
    else
        self:HideButton()

        local con=self.parent.LevelChangeEvent:Connect(function(level)
            self:UpdData(level)
        end)
        table.insert( self.ConList,con)
    
        self:UpdData(self.DataStore:GetData("base").level)
    end


end;

function M.HideButton(self)

    HomeGui.insts.Rebirth.button.Visible=false
end

function M.ShowButton(self)
    HomeGui.insts.Rebirth.button.Visible=true
    self:dtor()
end

function M.UpdData(self,level)
    local nextLevel=Rebirth_Cfg[0]["requiredLevel"]
    if level>=nextLevel then
        self:ShowButton()
    end
    
    if self.DataStore:GetData("base").rebirth>0 then
        self:ShowButton()
    end

end



function M.dtor(self)
    for k,v in pairs(self.ConList) do
       v:Disconnect()
    end
    self.ConList={}
   M.super.dtor(self);
end;

return M